﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO
{
    public static class HoaDonSPDAO
    {
        public static List<HOADON_SP> layDSHDSP()
        {
            QL_HuongRungEntities db = new QL_HuongRungEntities();
            List<HOADON_SP> arrHDSP = db.HOADON_SP.ToList();
            return arrHDSP;
        }

        public static int layMaHDLonNhat()
        {
            QL_HuongRungEntities db = new QL_HuongRungEntities();
            try
            {
                int maHD = db.HOADON_SP.Max(p => p.MaHDSP);
                return maHD;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public static bool themHoaDonSP(HOADON_SP hoaDonSP)
        {
            try
            {
                QL_HuongRungEntities db = new QL_HuongRungEntities();
                db.HOADON_SP.Add(hoaDonSP);
                db.SaveChanges();
                return true;
            }
            catch (Exception ex) { return false; }
        }

        public static bool capNhatHoaDon(HOADON_SP hoaDon)
        {
            try
            {
                QL_HuongRungEntities db = new QL_HuongRungEntities();
                HOADON_SP hd = db.HOADON_SP.Find(hoaDon.MaHDSP);
                hd.CTHD_SP = hoaDon.CTHD_SP;
                db.SaveChanges();
                return true;
            }
            catch (Exception ex) { return false; }
        }
    }
}
